package com.zte.coding.math;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-2-19
 * Time: 上午12:41
 * To change this template use File | Settings | File Templates.
 */
public class Probability {

    public static double calculateNonA(double probabilityA) throws Exception {
        if (probabilityA < 0 || probabilityA > 1) {
            throw new Exception();
        }
        return 1 - probabilityA;
    }

    public static double calculateAAndB(double probabilityA, double probabilityB) throws Exception {
        if (probabilityA < 0 || probabilityA > 1 || probabilityB < 0 || probabilityB > 1) {
            throw new Exception();
        }
        return probabilityA * probabilityB;
    }

    public static double calculateAOrB(double probabilityA, double probabilityB) throws Exception {
        if (probabilityA < 0 || probabilityA > 1 || probabilityB < 0 || probabilityB > 1) {
            throw new Exception();
        }
        return probabilityA + probabilityB - probabilityA * probabilityB;
    }
}
